package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.NutsNetGoodsInfoDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.NutsNetGoodsInfo;

/**
 * @Description 坚果网络商品信息DAO层操作
 * @author Administrator
 * @time 2012-08-28
 */
@Repository("nutsNetGoodsInfoDAO")
public class NutsNetGoodsInfoDAOImpl extends SuperDAO<NutsNetGoodsInfo>
		implements NutsNetGoodsInfoDAO {

	/**
	 * 坚果网络商品插入
	 * 
	 * @param nutsNetGoodsInfo
	 */
	@Override
	public void insert(NutsNetGoodsInfo nutsNetGoodsInfo) {
		this.getSqlSession().insert(
				"mybatis.xml.NutsNetGoodsInfoMapper.insert", nutsNetGoodsInfo);
	}

	/**
	 * 坚果网络商品更新
	 * 
	 * @param nutsNetGoodsInfo
	 */
	@Override
	public void update(NutsNetGoodsInfo nutsNetGoodsInfo) {
		this.getSqlSession().update(
				"mybatis.xml.NutsNetGoodsInfoMapper.update", nutsNetGoodsInfo);

	}

	/**
	 * 坚果网络商品，单条记录查询
	 * 
	 * @param goodsId
	 *            坚果商品ID
	 */
	@Override
	public NutsNetGoodsInfo queryById(String goodsId) {
		NutsNetGoodsInfo nutsNetGoodsInfo = null;
		nutsNetGoodsInfo = this.getSqlSession().selectOne(
				"mybatis.xml.NutsNetGoodsInfoMapper.query", goodsId);

		return nutsNetGoodsInfo;

	}

	/**
	 * 分页查询
	 * 
	 * @param nutsNetGoodsInfo
	 * @return
	 */
	@Override
	public Pagination<NutsNetGoodsInfo> queryPaginationList(
			NutsNetGoodsInfo nutsNetGoodsInfo) {
		Pagination<NutsNetGoodsInfo> paginationList = null;
		Integer rowCount = queryRowCount(nutsNetGoodsInfo);

		nutsNetGoodsInfo.calculate();
		List<NutsNetGoodsInfo> list = queryResultList(nutsNetGoodsInfo);
		paginationList = this.queryPagination(rowCount, list, nutsNetGoodsInfo);

		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param pageInruire
	 * @return
	 */
	private Integer queryRowCount(NutsNetGoodsInfo nutsNetGoodsInfo) {
		Integer rowCount = 0;
		rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.NutsNetGoodsInfoMapper.queryRowCount",
				nutsNetGoodsInfo);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param nutsNetGoodsInfo
	 * @return
	 */
	private List<NutsNetGoodsInfo> queryResultList(
			NutsNetGoodsInfo nutsNetGoodsInfo) {
		List<NutsNetGoodsInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.NutsNetGoodsInfoMapper.queryResultList",
				nutsNetGoodsInfo);
		return list;
	}

	/**
	 * 查询坚果网络原始商品表中的所有商品
	 * 
	 * @date 2012-12-01
	 * @return
	 */
	@Override
	public List<NutsNetGoodsInfo> queryAllGoodsInfo(NutsNetGoodsInfo info) {
		List<NutsNetGoodsInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.NutsNetGoodsInfoMapper.queryAllGoodsInfo",info);
		return list;
	}

	@Override
	public void updateState(NutsNetGoodsInfo nutsNetGoodsInfo) {
		this.getSqlSession().update(
				"mybatis.xml.NutsNetGoodsInfoMapper.updateState",
				nutsNetGoodsInfo);
	}

	/**
	 * 查询符合条件的商品编号
	 * 
	 * @param nutsNetGoodsInfo
	 * @return
	 */
	@Override
	public List<NutsNetGoodsInfo> queryAllGoodsId(NutsNetGoodsInfo info) {
		List<NutsNetGoodsInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.NutsNetGoodsInfoMapper.queryAllGoodsId", info);
		return list;
	}

	@Override
	public List<String> queryAllGoodsIdNoCondition() {
		List<String> goodsIdList = this
				.getSqlSession()
				.selectList(
						"mybatis.xml.NutsNetGoodsInfoMapper.queryAllGoodsIdNoCondition");
		return goodsIdList;
	}

}
